package com.gk.controller;

import com.alibaba.fastjson.JSON;
import com.gk.http.entity.HttpResult;
import com.gk.http.service.GetGkDataService;
import com.gk.service.InBillService;
import com.gk.service.OtherBillService;
import com.gk.service.OutBillService;
import com.gk.service.StockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("bill")
@Api(tags = "单据")
@Slf4j
public class BillController {
    @Autowired
    private InBillService inBillService;
    @Autowired
    private OutBillService outBillService;

    @GetMapping("/uploadCgBillToGk")
    @ApiOperation(value = "上传采购订单到国控", response = HttpResult.class)
    public HttpResult uploadCgBillToGk(String billCode) {
        return inBillService.CgBillUpload(billCode);
    }

    @GetMapping("/uploadXsBackBillToGk")
    @ApiOperation(value = "上传销售退货单到国控", response = HttpResult.class)
    public HttpResult uploadXsBackBillToGk(String billCode) {
        return inBillService.XsBackBillUpload(billCode);
    }


    @GetMapping("/uploadXsBillToGk")
    @ApiOperation(value = "上传销售单到国控", response = HttpResult.class)
    public HttpResult uploadXsBillToGk(String billCode) {
        return outBillService.XsBillUpload(billCode);
    }

    @GetMapping("/uploadCgBackBillToGk")
    @ApiOperation(value = "上传采购退货到国控", response = HttpResult.class)
    public HttpResult uploadCgBackBillToGk(String billCode) {
        return outBillService.CgBackBillUpload(billCode);
    }

    @GetMapping("/uploadCgLoessBillToGk")
    @ApiOperation(value = "上传报损单", response = HttpResult.class)
    public HttpResult uploadCgLoessBillToGk(String billCode) {
        return outBillService.LoessBillUpload(billCode);
    }

    @Autowired
    private GetGkDataService getGkDataService;

    @GetMapping("/getGkRkData")
    @ApiOperation(value = "获取国控入库数据", response = HttpResult.class)
    public Object getGkRkData(String billCode) {
        return getGkDataService.getGkInStockData(billCode);
    }

    @GetMapping("/getGkCkData")
    @ApiOperation(value = "获取国控出库数据", response = HttpResult.class)
    public Object getGkCkData(String billCode) {
        return getGkDataService.getGkOutStockData(billCode);
    }

    @Resource
    private OtherBillService otherBillService;

    @GetMapping("/getGkStockAdjustData")
    @ApiOperation(value = "获取国控库存调整数据", response = HttpResult.class)
    public Object getGkStockAdjustData() {//@RequestBody String str
        log.info("获取国控库存调整数据");
        otherBillService.AddGuoYaoStockAdjustBillToQF("");
        return null;
//        return getGkDataService.getGkStockAdjustData();
    }

    @Resource
    private StockService stockService;

    @GetMapping("/getGkGoodsStocks")
    @ApiOperation(value = "获取国控库存余额", response = HttpResult.class)
    public Object getGkGoodsStocks() {//@RequestBody String str
        log.info("生成库存调整单据");
        //TODO 获取好数据以后,调用插入接口
        stockService.addGkGoodsStocksToQF("");
        return null;
//        return getGkDataService.getGkStockAdjustData();
    }

    @GetMapping("/addGkStockAdjust")
    @ApiOperation(value = "生成库存调整单据", response = HttpResult.class)
    public Object addGkStockAdjust() {//@RequestBody String str
        log.info("生成库存调整单据");
        //TODO 获取好数据以后,调用插入接口
        otherBillService.CreateQFBatchnoChangeBill();
        otherBillService.CreateQFStopSaleBill();
        return null;
//        return getGkDataService.getGkStockAdjustData();
    }


    @GetMapping("/createQFYHMaintainRecord")
    @ApiOperation(value = "生成养护记录", response = HttpResult.class)
    public Object createQFYHMaintainRecord() {
        log.info("生成养护记录");
        //TODO 获取好数据以后,调用插入接口
        otherBillService.CreateQFYHMaintainRecord();
        return null;
//        return getGkDataService.getGkStockAdjustData();
    }

    public Object calcelOrederBill(String billCode) {
        return getGkDataService.getGkOutStockData(billCode);
    }


}
